<template>
  <!-- 模板部分保持不变 -->
  <div class="login-background">
    <!-- 添加 3D 背景容器 -->
    <div id="threejs-container"></div>
    <div class="login-container">
      <el-card class="login-card">
        <template #header>
          <h1 class="login-title">JRP反向代理</h1>
        </template>
        <el-form @submit.prevent="handleLogin" label-width="80px">
          <el-form-item label="用户名">
            <el-input v-model="username" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="password" type="password" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" native-type="submit" class="login-button">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref} from 'vue';
import { useRouter } from 'vue-router';
import { login } from '../api/api';

const router = useRouter();
const username = ref('');
const password = ref('');

const handleLogin = async () => {
  try {
    // 调用封装好的登录接口
    const response = await login(username.value, password.value);

    // 假设接口返回的状态码为 200 表示登录成功
    if (response.status === 200) {
      // 登录成功，跳转到主页
      router.push('/');
    } else {
      // 登录失败，可根据实际情况处理错误信息
      console.error('登录失败:', response.message);
    }
  } catch (error) {
    // 处理请求错误
    console.error('请求出错:', error);
  }
};

</script>

<style scoped>
/* 去掉滚动条 */
body {
  overflow: hidden; 
  margin: 0px;
}

.login-background {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

#threejs-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.login-container {
  width: 400px; 
}

.login-card {
  border-radius: 10px; 
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 
}

.login-title {
  color: #333; 
  text-align: center;
  font-size: 24px; /* 减小字体大小 */
  margin: 10px 0; /* 减小上下外边距 */
}

.login-button {
  width: 100%;
  margin-top: 10px; 
  border-radius: 5px; 
}
</style>